package edu.bailie.springmvc.controller;

import edu.bailie.springmvc.pojo.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {
	@RequestMapping(value = "/")
	public String hello(){
		System.out.println("正在处理请求....");
		// 返回逻辑视图名称（决定跳转到哪个页面）
		return "index";
	}

	@RequestMapping(value = {"/hello1","/pl1"})
	public String hello1(HttpServletRequest request){

		String uname = request.getParameter("username");
		String passwd = request.getParameter("password");
		System.out.println("正在处理请求....");
		System.out.println(uname+"      "+passwd);
		// 返回逻辑视图名称（决定跳转到哪个页面）
		return "first";
	}

	@RequestMapping(value = {"/hello2","/pl2"})
	public String hello2(
		@RequestParam(value = "username")
		String uname,
		@RequestParam(value = "password",required=false,defaultValue = "1555589555")
		String passwd
	){

		System.out.println("正在处理请求....");
		System.out.println(uname+"      "+passwd);
		// 返回逻辑视图名称（决定跳转到哪个页面）
		return "first";
	}

	@RequestMapping(value = {"/hello3","/pl3"})
	public String hello3(User user){


		String pwd = user.getPassword();
		String un = user.getUsername();

		System.out.println("正在处理请求....");
		System.out.println(user);
		System.out.println(un+"     "+pwd);
		// 返回逻辑视图名称（决定跳转到哪个页面）
		return "first";
	}
}
